<template>
  <div>
    <div class="top">
      <h2>{{ list.product_name }}</h2>
      <div class="div">
        <span>概述</span>
        <span>参数</span>
        <span>用户评价</span>
      </div>
    </div>
    <hr class="hr" />
    <div class="center">
      <div class="lun">
        <el-carousel indicator-position="outside" height="530px">
          <el-carousel-item v-for="(item, index) in tu" :key="index">
            <img
              :src="`http://101.132.181.9/api/${item.product_picture}`"
              alt=""
            />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="right">
        <h2>{{ list.product_name }}</h2>
        <p>{{ list.product_intro }}</p>
        <font>小米自营</font>
        <div class="sp">
          <span class="s1">{{ list.product_selling_price }}元</span>
          <s>{{ list.product_price }}元</s>
        </div>
        <hr class="h" />
        <div class="money">
          <div class="mo">
            <span>{{ list.product_name }}</span>
            <div class="m">
              <span>{{ list.product_selling_price }}元</span>&nbsp;&nbsp;
              <s>{{ list.product_price }}元</s>
            </div>
          </div>
          <p>总计:{{ list.product_selling_price }}元</p>
        </div>

        <el-button class="b1" @click="addCard">加入购物车</el-button>
        <el-button class="b2" @click="love">喜欢</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getDetail, Lunbotu, getAdd, addCart } from "@/api/user";
export default {
  data() {
    return {
      list: [],
      tu: [],
    };
  },
  mounted() {
    this.detail(this.$route.query.productID);
    this.getlun();
  },
  methods: {
    //点击加入购物车
    async addCard() {
      if (!this.$store.getters.userID) {
        this.$message.error("请先登录");
        return this.$store.commit("editshow");
      }
      const res = await addCart({
        product_id: this.$route.query.productID,
        user_id: this.$store.getters.userID,
      });
      this.$message.success("添加成功");
      window.location.reload()
      console.log(res.data);
    },
    //点击喜欢收藏
    async love() {
      if (!this.$store.getters.userID) {
        this.$message.error("请先登录");
        return this.$store.commit("editshow");
      }
      const res = await getAdd({
        product_id: this.$route.query.productID,
        user_id: this.$store.getters.userID,
      });
      this.$message.success("收藏成功");
      console.log(res.data);
    },
    //轮播图
    async getlun() {
      const res = await Lunbotu({ productID: this.$route.query.productID });
      // console.log(res.data);
      this.tu = res.data.ProductPicture;
    },
    //获取数据
    async detail(productID) {
      //   // console.log(a);
      const res = await getDetail({ productID });
      console.log(res.data);
      this.list = res.data.Product[0];
    },
  },
};
</script>

<style scoped lang="scss">
.top {
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 70px;
  background: #fff !important;
  h2 {
    font-size: 25px;
    font-weight: normal;
    margin-left: 170px;
  }
  div {
    margin-right: 140px;
    span {
      padding-right: 20px;
    }
  }
}
.hr {
  box-shadow: 0 5px 5px rgb(0 0 0 / 7%);
}
.center {
  display: flex;
  background: #fff;
  .lun {
    height: 550px;
    width: 600px;
    margin-left: 170px;
    img {
      width: 100%;
      height: 500px;
    }
  }
  .right {
    flex: 1;
    margin-right: 140px;
    h2 {
      font-size: 25px;
      font-weight: normal;
      margin-top: 30px;
    }
    p {
      font-size: 15px;
      color: #ccc;
      margin: 10px 0 10px 0;
    }
    font {
      color: orangered;
    }
    .sp {
      margin-top: 30px;
      .s1 {
        font-size: 20px;
        color: orangered;
      }
      s {
        font-size: 14px;
        padding-left: 10px;
        color: #ccc;
      }
    }
    .h {
      margin-top: 40px;
      color: #ccc;
    }
    .money {
      background: #f9f9fa;
      height: 142px;
      width: 100%;
      margin-top: 50px;
      .mo {
        display: flex;
        justify-content: space-around;
        span,
        .m {
          margin-top: 20px;
        }
      }
      p {
        font-size: 24px;
        color: #ff6700;
        padding-top: 20px;
        margin-left: 100px;
      }
    }
    .b1 {
      background-color: #ff6700;
      width: 285px;
      height: 55px;
      color: #fff;
      margin-top: 30px;
    }
    .b2 {
      background-color: gray;
      width: 285px;
      height: 55px;
      margin-top: 30px;
      color: #fff;
    }
  }
}
</style>
